home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / jreboot.arc / JREBOOT.ASM next >
Encoding:
Assembly Source File  |  1987-03-03  |  8.6 KB  |  279 lines

  1.         name    JREBOOT
  2.         page    60,132
  3.         title   'JREBOOT - Reboot JBOOT.BIN, Version 3.41'
  4.  
  5.     COMMENT ~
  6.  
  7.      This program reboots an IBM PC/XT which has a TallTree JRAM3 card
  8. and the JBOOT.BIN device driver.  Its usage is:
  9.      JREBOOT                 Warm reset
  10.      JREBOOT W or JREBOOT w  Warm reset
  11.      JREBOOT -               ROM reset
  12.      JREBOOT R or JREBOOT r  ROM reset
  13.      JREBOOT C or JREBOOT c  Cold reboot
  14.      JREBOOT K or JREBOOT k  Cold reboot
  15.  
  16.      If DOS is earlier than version 2, The NUL device is not loaded or
  17. JBOOT device is not loaded, the program exits with return code 1.  If
  18. the usage is wrong, it exits with return code 2.  While JBOOT should
  19. never return, if it does, the program exits with return code 3.
  20.  
  21.      It is very sensitive to the exact version of JBOOT.BIN.  To check it
  22. for your software, assemble and list JBOOT.ASM from the TallTree disk,
  23. then compare the offsets of the labels warmreset, coldboot and romreset
  24. to their values as constants below.  If they are different, change the
  25. constants.
  26.  
  27.      Technically, this is very dirty code.  Its main function is to 
  28. synthesize a far call into $JBOOT, the JBOOT device driver.  Since I
  29. can not find an 8088 instruction which gives an indirect far call, I
  30. have been forced to treat the rebooting instruction as data.  Thus the
  31. "DB 9A" and the double word reboot very near the end of the code segment
  32. becomes a far call to the proper point in JBOOT.BIN.
  33.  
  34.      ACKNOWLEDGEMENT.  I have marked sections of code which I have copied
  35. from DEV11.ARC, which is a program to list device drivers, Copywrite (c)
  36. 1984 by Ray Duncan and modified in 1986 by Brian J. Larson for DOS 3.2.
  37. Mr.Duncan has given me permission to distribute this program.
  38.  
  39. ~
  40.  
  41. warmreset EQU    03E4H    ; Offset of label in JBOOT.BIN
  42. coldboot  EQU    0455H    ; Offset of label in JBOOT.BIN
  43. romreset  EQU    048AH    ; Offset of label in JBOOT.BIN
  44.  
  45. ht    EQU    9    ; Horizontal tab
  46.  
  47. ; Code from DEV11 starts here
  48. cr      equ     0dh             ;ASCII carriage return
  49. lf      equ     0ah             ;ASCII line feed
  50. blank    equ    20h        ;ASCII space code
  51. eom    equ    '$'        ;end of string marker
  52.  
  53.  
  54. cseg    segment    para public 'CODE'
  55.  
  56.     assume    cs:cseg,ds:data,es:data,ss:stack
  57.  
  58. ; Code from DEV11 temporarily ends
  59.  
  60. jreboot    PROC    FAR             ;entry point from PC-DOS
  61.  
  62.     MOV    SI,80H    ; Offset of number of characters on
  63.             ; command line
  64.     LODSB        ; Number of characters on command line
  65.             ; SI points to first character if there
  66.             ; are any
  67.     OR    AL,AL    ; Are there any?
  68.     JZ    set_warmreset    ; No.  Set warm reset.
  69.     XOR    AH,AH    ; Convert byte to word
  70.     MOV    CX,AX    ; Number of characters => CX
  71. check_white:
  72.     LODSB        ; Command line character => AL
  73.             ; Increment SI
  74.     CMP    AL,blank    ; Is the character a space?
  75.     JE    check_white    ; Get next character
  76.     CMP    AL,ht    ; Is it a horizontal tab?
  77.     JE    check_white    ; Get next character
  78.     CMP    AL,cr    ; Is it a carriage return?
  79.     JE    set_warmreset    ; Yes.  Only white characters on
  80.             ; command line.
  81.     SUB    SI,81H    ; Number of characters read
  82.     CMP    SI,CX    ; Is this the last character?
  83.     JNZ    usage_error    ; No.  Print error message and exit.
  84.     CMP    AL,'-'    ; Is it a dash?
  85.     JE    set_romreset    ; Yes.  Set ROM reset
  86.     AND    AL,5FH    ; If it is a letter, set it to
  87.             ; upper case
  88.     CMP    AL,'W'    ; Is it a W?
  89.     JE    set_warmreset    ; Yes.  Set warm reset
  90.     CMP    AL,'R'    ; Is it a R?
  91.     JE    set_romreset    ; Yes.  Set ROM reset
  92.     CMP    AL,'K'    ; Is it a K?
  93.     JE    set_coldboot    ; Yes.  Set cold reboot
  94.     CMP    AL,'C'    ; Is it a K?
  95.     JE    set_coldboot    ; Yes.  Set cold reboot
  96.  
  97. usage_error:
  98.     MOV    AX,data    ; Establish addressability
  99.     MOV    DS,AX
  100.     MOV    AH,40H    ; DOS write handle function
  101.     MOV    BX,2    ; Handle for Standard Error
  102.     MOV    CX,usage_length    ; Number of characters to write
  103.     MOV    DX,OFFSET usage    ; Pointer to usage message
  104.     INT    21H    ; Write it
  105.     MOV    AX,4C02H    ; Exit with return code 2
  106.     INT    21H
  107.     
  108. set_warmreset:
  109.     MOV    BX,warmreset    ; Offset of warm reset in JBOOT
  110.     JMP    SHORT set_offset_end
  111.  
  112. set_romreset:
  113.     MOV    BX,romreset    ; Offset of ROM reset in JBOOT
  114.     JMP    SHORT set_offset_end
  115.  
  116. set_coldboot:
  117.     MOV    BX,coldboot    ; Offset of cold boot in JBOOT
  118.     JMP    SHORT set_offset_end    ; Defensive programming
  119.  
  120. set_offset_end:
  121.     MOV    WORD PTR CS:reboot,BX    ; Offset in JBOOT to junp to
  122.  
  123.     MOV    AX,data    ; Establish addressibility
  124.     MOV    DS,AX
  125.     MOV    ES,AX
  126.  
  127. ; Code from DEV11 restarts here.  I added a few SHORT's to the jmp
  128. ; instructions.  LP
  129.         mov     ah,30h        ;check version of PC-DOS.    
  130.         int     21h
  131.         cmp     al,2
  132.         jae     dev1        ;proceed, DOS 2.0 or greater.
  133.         mov     dx,offset msg2  ;DOS 1.x --- print error message.
  134.     jmp    dev6
  135.  
  136. dev1:    mov    cx,ax        ;save DOS version number.
  137.     mov    ah,15        ;now try and open the "NUL" device.
  138.     mov    dx,offset nulfcb
  139.     int    21h
  140.     or    al,al        ;opened successfully?
  141.     jz    dev2        ;yes, jump.
  142.     mov    dx,offset msg1    ;no, print error msg and exit.
  143.     jmp    SHORT dev6
  144.  
  145. dev2:                ;Pick up double pointer to device 
  146.                 ;driver chain out of reserved
  147.                 ;area in fcb.  This area is mapped
  148.                 ;differently in DOS 2.x and DOS 3.x.
  149.     cmp    cl,2        ;is this DOS 2.x?
  150.     ja    dev3        ;no, jump.
  151.     mov    bx,word ptr nulfcb+25
  152.     mov    es,word ptr nulfcb+27
  153.     jmp    SHORT dev4
  154.  
  155. dev3:                ;come here if DOS 3.0 or greater.
  156.     cmp    ch,2        ;compare minor - DOS 3.2 or greater?
  157.     jae    dev32        ;yes, jump.
  158.     mov    bx,word ptr nulfcb+26
  159.     mov    es,word ptr nulfcb+28
  160.     jmp    SHORT dev4
  161.  
  162. dev32:                ;come here if DOS 3.2 or above
  163.     mov    bx,48h        ;value at nulfcb+26 is C2h but NUL is at 48h
  164.     mov    es,word ptr nulfcb+28
  165.  
  166. dev4:
  167.                 ;pick up addr of next header.
  168.     les    bx,dword ptr es:[bx]
  169.     cmp    bx,-1        ;found last one yet?
  170.  
  171. ; Restarted code from DEV11 temporarily ends here
  172.  
  173.     JE    no_jboot    ; JBOOT device driver is not loaded
  174.     TEST    ES:[BX+4],08000H    ; Is this a character device?  Bit
  175.             ; 15 of attribute word is set if yes.
  176.     JZ    dev4    ; No.  Get next header
  177.     MOV    SI,OFFSET jboot_name    ; "$JBOOT  "
  178.     MOV    DI,BX    ; Offset of start of header
  179.     ADD    DI,10    ; Offset of device name
  180.     MOV    CX,8    ; Number of characters in name
  181.     REPE    CMPSB    ; Is this the JBOOT device driver
  182.     JNE    dev4    ; No.  Get next header.
  183.     MOV    AX,ES    ; Segment of JBOOT device driver
  184.     MOV    WORD PTR CS:reboot+2,AX
  185.             ; Save for FAR CALL
  186.     ADD    WORD PTR CS:reboot,BX    ; Offset of JBOOT device driver to
  187.             ; offset of entry
  188.     PUSHF        ; To fake an interrupt
  189.  
  190. ; This is the data which becomes the far call to the interior of JBOOT.BIN.
  191. ; Theoretically, there should be no return, because JBOOT should reboot
  192.     DB    9AH    ; Op code for Intersegment FAR CALL
  193. reboot    DD    (?)    ; Offset, segment in JBOOT to reboot
  194.  
  195.     MOV    AX,data    ; This is the impossible return.  If
  196.             ; it happens, you had better 
  197.             ; reestablish addressibility
  198.     MOV    DS,AX
  199.     MOV    AH,40H    ; Write function for handles
  200.     MOV    BX,01    ; Handle for Standard Error
  201.     MOV    CX,jboot_returns_msg_length
  202.             ; Number of bytes to write
  203.     MOV    DX,OFFSET jboot_returns_msg
  204.             ; Offset of error message
  205.     INT    21H    ; Write it
  206.     MOV    AX,4C03H    ; Exit with return code 3
  207.     INT    21H
  208. no_jboot:
  209.     MOV    DX,OFFSET no_jboot_msg
  210.             ; No JBOOT message
  211.     JMP    SHORT dev6    ; Defensive programming
  212.  
  213. ; Code from DEV11 restarts here
  214.  
  215. dev6:     mov    ah,9        ;print the string whose address
  216.     int    21h        ;is in DX.
  217.  
  218. ; Restarted code from DEV11 temporarily ends here
  219.  
  220.     MOV    AX,4C01H    ; Exit with return code 1
  221.     INT    21H
  222.  
  223. jreboot    ENDP
  224.  
  225. ; Code from DEV11 restarts here
  226.  
  227. cseg    ends
  228.  
  229.  
  230. data    segment para public 'DATA'
  231.  
  232. msg1    db    cr,lf
  233.     db    'Failed to open NUL device.'
  234.     db    cr,lf,eom
  235.  
  236. msg2    db      cr,lf
  237.         db      'Requires DOS version 2 or greater.'
  238.         db      cr,lf,eom
  239.  
  240. ; Restarted code from DEV11 temporarily ends here
  241.  
  242. no_jboot_msg DB     cr,lf
  243.     DB    "JBOOT device driver is not loaded"
  244.     DB    cr, lf, eom
  245.  
  246. usage    DB    cr, lf, "     This program reboots an IBM PC/XT which "
  247.     DB    "has a TallTree JRAM3 card", cr, lf
  248.     DB    "and the JBOOT.BIN device driver.  Its usage is:", cr, lf
  249.     DB    "     JREBOOT                 Warm reset", cr, lf
  250.     DB    "     JREBOOT W or JREBOOT w  Warm reset", cr, lf
  251.     DB    "     JREBOOT -               ROM reset", cr, lf
  252.     DB    "     JREBOOT R or JREBOOT r  ROM reset", cr, lf
  253.     DB    "     JREBOOT C or JREBOOT c  Cold reboot", cr, lf
  254.     DB    "     JREBOOT K or JREBOOT k  Cold reboot", cr, lf
  255. usage_length = $ - OFFSET usage
  256.  
  257. jboot_returns_msg DB cr,lf
  258.     DB    "JBOOT should have rebooted instead of returning here"
  259.     DB    cr,lf
  260. jboot_returns_msg_length = $ - OFFSET jboot_returns_msg
  261. jboot_name DB    "$JBOOT  "    ; Name of JBOOT device driver
  262.  
  263. ; Code from DEV11 restarts here
  264.                 ;fcb to open NUL device
  265. nulfcb    db    0        ;drive
  266.     db    'NUL'        ;name of NUL device
  267.     db    8 dup (' ')
  268.     db    25 dup (0)
  269. data    ends    
  270.  
  271.  
  272. stack   segment para stack 'STACK'
  273.         db      64 dup (?)
  274. stack   ends
  275.  
  276. ; Code from DEV11 ends here
  277.  
  278.         END     jreboot
  279.